package ModelLayer;
import java.util.*;


public class DVDCol
{   public ArrayList<DVD> d;
    public DVD dvd;
    // instance variables - replace the example below with your own

    /**
     * Constructor for objects of class DVDCol
     */
    public DVDCol()
    { 
        d = new ArrayList<DVD>();
    }

    /**
     * Methods for the DVD ArrayList,which stores all DVD Class instances:
     * Add,return AllDVDs,find a DVD after its ID,find a Copy of a DVD using the Serial Number of the Copy and delete a DVD.
     */
    public void addDVD(DVD _newDVD)
    {
        d.add(_newDVD);
    }

    public ArrayList<DVD> getDVDCol()
    { 
        return d;
    }

    public DVD findDVD(long _id)
    { 
        DVD tempDVD = null;
        int i=0;
        boolean found=false;
        while(i<d.size() && !found)
        {
            DVD dvd = d.get(i);
            if(dvd.getID()==_id)
            { 
                tempDVD = dvd;
                found = true;
            }
            else
                i++;
        }
        return tempDVD;
    }

    public long findCopyOfDVD(String _serialNumber)
    {
        long dvdID = 0;
        //this method is to search the container for a person
        //with an id-number equal to the parameter id
        //when person is found, the method is to call print-methods in the TUI layer
        int i= 0;
        boolean found= false;
        while ( !found && i<d.size())
        {
            DVD dvd = d.get(i);
            if (dvd.hasCopy(_serialNumber))
            {
                dvdID = dvd.getID();
                found= true;
            }
            else
                i++;
        } // end while
        return dvdID;
    }
    public String CopyList()
    {   String str;
        str=dvd.PrintAllCopies();
        return str;
        
    }
    public void deleteDVD(DVD _d)
    {
        d.remove(_d);
    }

}
